

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 1. Maven 项目pom.xml 代码 123456789101112131415161718192021222324252627282930&lt;project xmlns&#x3D;&quot;http:&#x2F;&#x2F;maven.apache.org&#x2F;POM&#x2F;4.0.0&quot; xmlns:xsi&#x3D;&quot;http:&#x2F;&#x2F;www.w3.org&#x2F;2001&#x2F;XMLSchema-instanc">
<meta property="og:type" content="article">
<meta property="og:title" content="Hadoop _ Java实现操作 HDFS 读取、获取、下载、上传、删除文件">
<meta property="og:url" content="http://example.com/2021/04/04/Hadoop%20_%20Java%E5%AE%9E%E7%8E%B0%E6%93%8D%E4%BD%9C%20HDFS%20%E8%AF%BB%E5%8F%96%E3%80%81%E8%8E%B7%E5%8F%96%E3%80%81%E4%B8%8B%E8%BD%BD%E3%80%81%E4%B8%8A%E4%BC%A0%E3%80%81%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 1. Maven 项目pom.xml 代码 123456789101112131415161718192021222324252627282930&lt;project xmlns&#x3D;&quot;http:&#x2F;&#x2F;maven.apache.org&#x2F;POM&#x2F;4.0.0&quot; xmlns:xsi&#x3D;&quot;http:&#x2F;&#x2F;www.w3.org&#x2F;2001&#x2F;XMLSchema-instanc">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-04-04T15:53:17.000Z">
<meta property="article:modified_time" content="2022-08-22T15:44:13.307Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Hadoop">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary_large_image">
  
  
  
  <title>Hadoop _ Java实现操作 HDFS 读取、获取、下载、上传、删除文件 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Hadoop _ Java实现操作 HDFS 读取、获取、下载、上传、删除文件"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2021-04-04 23:53" pubdate>
          2021年4月4日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7.6k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          64 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Hadoop _ Java实现操作 HDFS 读取、获取、下载、上传、删除文件</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="1-Maven-项目pom-xml-代码"><a href="#1-Maven-项目pom-xml-代码" class="headerlink" title="1. Maven 项目pom.xml 代码"></a>1. Maven 项目pom.xml 代码</h1><hr>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span> <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span><br><span class="hljs-tag">         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>cn.hdfs-java-api<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>hdfs-java-api<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">packaging</span>&gt;</span>war<span class="hljs-tag">&lt;/<span class="hljs-name">packaging</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.0-SNAPSHOT<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>hdfs-java-api<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">url</span>&gt;</span>http://maven.apache.org<span class="hljs-tag">&lt;/<span class="hljs-name">url</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>hadoop-hdfs<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.3.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>hadoop-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.3.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.hadoop<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>hadoop-common<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.3.0<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">finalName</span>&gt;</span>hdfs-java-api-maven<span class="hljs-tag">&lt;/<span class="hljs-name">finalName</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h1 id="2-具体代码实现"><a href="#2-具体代码实现" class="headerlink" title="2. 具体代码实现"></a>2. 具体代码实现</h1><hr>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> org.apache.hadoop.conf.Configuration;<br><span class="hljs-keyword">import</span> org.apache.hadoop.fs.*;<br><span class="hljs-keyword">import</span> java.io.*;<br><span class="hljs-keyword">import</span> java.text.SimpleDateFormat;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">con</span> &#123;<br>    <span class="hljs-keyword">static</span> Configuration conf ;  <span class="hljs-comment">// 创建hdfs连接对象，类型为Configuration</span><br>    <span class="hljs-keyword">static</span> FileSystem fs ;       <span class="hljs-comment">// 根据连接的实例对象Configuration创建文件对象</span><br>    <span class="hljs-keyword">static</span> Path filePath ;       <span class="hljs-comment">// 创建记录操作目录的path对象</span><br>    <span class="hljs-keyword">static</span> Path remotePath ;       <span class="hljs-comment">// 创建保存文件的目录</span><br>    <span class="hljs-keyword">static</span> Path localPath;       <span class="hljs-comment">// 创建本地文件目录</span><br>    <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">remoteFilePath</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;&quot;</span>;<br>    <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">localFilePath</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;&quot;</span>; <span class="hljs-comment">// 本地路径</span><br>    <span class="hljs-comment">// 构造函数初始化</span><br>    con() <span class="hljs-keyword">throws</span> IOException&#123;<br>        conf = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Configuration</span>();<br>        <span class="hljs-comment">// 获取hdfs-site.xml配置文件中的fs.default.name和fs.hdfs.impl参数</span><br>        conf.set(<span class="hljs-string">&quot;fs.default.name&quot;</span>, <span class="hljs-string">&quot;hdfs://localhost:9000&quot;</span>);<br>        conf.set(<span class="hljs-string">&quot;fs.hdfs.impl&quot;</span>, <span class="hljs-string">&quot;org.apache.hadoop.hdfs.DistributedFileSystem&quot;</span>);<br>        conf.set(<span class="hljs-string">&quot;dfs.client.block.write.replace-datanode-on-failure.policy&quot;</span>, <span class="hljs-string">&quot;NEVER&quot;</span>);<br>        conf.set(<span class="hljs-string">&quot;dfs.client.block.write.replace-datanode-on-failure.enable&quot;</span>, <span class="hljs-string">&quot;true&quot;</span>);<br>        fs = FileSystem.get(conf);<br>        filePath = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(<span class="hljs-string">&quot;/user/uni1024/text.txt&quot;</span>);<span class="hljs-comment">// 设置hdfs 命令操作的执行目录</span><br>        remotePath = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(<span class="hljs-string">&quot;/user/uni1024/&quot;</span>);<br>        localPath = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(<span class="hljs-string">&quot;/usr/local/hdfs-output/&quot;</span>);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">ls</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> IOException&#123;<br>        <span class="hljs-keyword">for</span> (FileStatus status : fs.listStatus(remotePath))&#123;<br>            <span class="hljs-type">StringBuffer</span> <span class="hljs-variable">x</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">StringBuffer</span>();<br>            x.append(status.getPermission() + <span class="hljs-string">&quot;    &quot;</span>);<br>            x.append(status.getReplication() + <span class="hljs-string">&quot;    &quot;</span>);<br>            x.append(status.getOwner() + <span class="hljs-string">&quot;    &quot;</span>);<br>            x.append(status.getGroup() + <span class="hljs-string">&quot;    &quot;</span>);<br>            <span class="hljs-type">SimpleDateFormat</span> <span class="hljs-variable">df</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">SimpleDateFormat</span>(<span class="hljs-string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span>);<span class="hljs-comment">//设置日期格式</span><br>            x.append(df.format(status.getModificationTime()));<br>            x.append(<span class="hljs-string">&quot;    &quot;</span> + status.getPath());<br>            System.out.println(x);<br>        &#125;<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">cat</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> IOException &#123;<br><br>        <span class="hljs-type">FSDataInputStream</span> <span class="hljs-variable">in</span> <span class="hljs-operator">=</span> fs.open(filePath);<br><br>        <span class="hljs-type">BufferedReader</span> <span class="hljs-variable">d</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BufferedReader</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">InputStreamReader</span>(in));<br>        <span class="hljs-type">String</span> <span class="hljs-variable">line</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-keyword">while</span> ((line = d.readLine()) != <span class="hljs-literal">null</span>) &#123;<br>            System.out.println(line);<br>        &#125;<br><span class="hljs-comment">//        String data = in.readUTF();</span><br><span class="hljs-comment">//        System.out.println(data);</span><br><span class="hljs-comment">//        in.close();</span><br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">get</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> IOException &#123;<br><br>        <span class="hljs-type">Path</span> <span class="hljs-variable">remotePath</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(remoteFilePath);<br>        <span class="hljs-type">File</span> <span class="hljs-variable">f</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(localFilePath);<br>        <span class="hljs-comment">/* 如果文件名存在，自动重命名(在文件名后面加上 _0, _1 ...) */</span><br>        <span class="hljs-keyword">if</span> (f.exists()) &#123;<br>            System.out.println(localFilePath + <span class="hljs-string">&quot; 已存在.&quot;</span>);<br>            <span class="hljs-type">Integer</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>            <span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) &#123;<br>                f = <span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(localFilePath + <span class="hljs-string">&quot;_&quot;</span> + i.toString());<br>                <span class="hljs-keyword">if</span> (!f.exists()) &#123;<br>                    localFilePath = localFilePath + <span class="hljs-string">&quot;_&quot;</span> + i.toString();<br>                    <span class="hljs-keyword">break</span>;<br>                &#125;<br>                i++;<br>            &#125;<br>            System.out.println(<span class="hljs-string">&quot;将重新命名为: &quot;</span> + localFilePath);<br>        &#125;<br><br>        <span class="hljs-comment">// 下载文件到本地</span><br>        <span class="hljs-type">Path</span> <span class="hljs-variable">localPath</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(localFilePath);<br>        fs.copyToLocalFile(remotePath, localPath);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">put</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        <span class="hljs-comment">/* 判断文件是否存在 */</span><br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">fileExists</span> <span class="hljs-operator">=</span> <span class="hljs-literal">false</span>;<br>        localPath = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(localFilePath);<br>        remoteFilePath = remoteFilePath + <span class="hljs-string">&quot;/&quot;</span> + localPath.getName();<br>        remotePath = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(remoteFilePath);<br>        <span class="hljs-type">String</span> <span class="hljs-variable">choice</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;append&quot;</span>; <span class="hljs-comment">// 若文件存在则追加到文件末尾</span><br>        <span class="hljs-keyword">if</span> (fs.exists(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(remoteFilePath))) &#123;<br>            fileExists = <span class="hljs-literal">true</span>;<br>            System.out.println(remoteFilePath + <span class="hljs-string">&quot; 已存在.&quot;</span>);<br>        &#125; <span class="hljs-keyword">else</span> &#123;<br>            System.out.println(remoteFilePath + <span class="hljs-string">&quot; 不存在.&quot;</span>);<br>        &#125;<br>        <span class="hljs-comment">/* 进行处理 */</span><br>        <span class="hljs-keyword">if</span> (!fileExists || choice.equals(<span class="hljs-string">&quot;overwrite&quot;</span>)) &#123; <span class="hljs-comment">// 文件不存在，则上传</span><br><br>            <span class="hljs-comment">/* fs.copyFromLocalFile 第一个参数表示是否删除源文件，第二个参数表示是否覆盖 */</span><br>            fs.copyFromLocalFile(<span class="hljs-literal">false</span>, <span class="hljs-literal">true</span>, localPath, remotePath);<br>            System.out.println(localFilePath + (fileExists == <span class="hljs-literal">true</span>?<span class="hljs-string">&quot; 已覆盖 &quot;</span>:<span class="hljs-string">&quot; 已上传 &quot;</span>) + remoteFilePath);<br><br>        &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (choice.equals(<span class="hljs-string">&quot;append&quot;</span>)) &#123; <span class="hljs-comment">// 选择追加</span><br>            <span class="hljs-type">Path</span> <span class="hljs-variable">remotePath</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(remoteFilePath);<br>            <span class="hljs-comment">/* 创建一个文件读入流 */</span><br>            <span class="hljs-type">FileInputStream</span> <span class="hljs-variable">in</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">FileInputStream</span>(localFilePath);<br>            <span class="hljs-comment">/* 创建一个文件输出流，输出的内容将追加到文件末尾 */</span><br>            <span class="hljs-type">FSDataOutputStream</span> <span class="hljs-variable">out</span> <span class="hljs-operator">=</span> fs.append(remotePath);<br>            <span class="hljs-comment">/* 读写文件内容 */</span><br>            <span class="hljs-type">byte</span>[] data = <span class="hljs-keyword">new</span> <span class="hljs-title class_">byte</span>[<span class="hljs-number">1024</span>];<br>            <span class="hljs-type">int</span> <span class="hljs-variable">read</span> <span class="hljs-operator">=</span> -<span class="hljs-number">1</span>;<br>            <span class="hljs-keyword">while</span> ((read = in.read(data)) &gt; <span class="hljs-number">0</span>)<br>                out.write(data, <span class="hljs-number">0</span>, read);<br>            System.out.println(localFilePath + <span class="hljs-string">&quot; 已追加至 &quot;</span> + remoteFilePath);<br>        &#125;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">rm</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> IOException&#123;<br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">result</span> <span class="hljs-operator">=</span> <span class="hljs-literal">false</span>;<br>        remotePath = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(remoteFilePath);<br>        result = fs.delete(remotePath, <span class="hljs-literal">false</span>);<br>        System.out.println(result == <span class="hljs-literal">true</span> ? (<span class="hljs-string">&quot;文件删除: &quot;</span> + remoteFilePath) : (<span class="hljs-string">&quot;操作失败（文件不存在或删除失败）&quot;</span>));<br>    &#125;<br><br>    <span class="hljs-comment">// 判断hdfs中是否存在path目录</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-type">boolean</span> <span class="hljs-title function_">isInHdfs</span><span class="hljs-params">(String path)</span> <span class="hljs-keyword">throws</span> IOException&#123;<br>        <span class="hljs-type">Path</span> <span class="hljs-variable">p</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(path);<br>        <span class="hljs-keyword">return</span> fs.exists(p);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">help</span><span class="hljs-params">()</span> &#123;<br>        System.out.println(<span class="hljs-string">&quot;-----------------------------------帮助文档------------------------------------\n&quot;</span> +<br>                <span class="hljs-string">&quot;\n&quot;</span> +<br>                <span class="hljs-string">&quot;ls  [hdfs目录]  # 查询hdfs服务器目录下的所有文件\n&quot;</span> +<br>                <span class="hljs-string">&quot;\n&quot;</span> +<br>                <span class="hljs-string">&quot;cat [hdfs文件目录]  # 查询hdfs服务器中文本文件的内容\n&quot;</span> +<br>                <span class="hljs-string">&quot;\n&quot;</span> +<br>                <span class="hljs-string">&quot;get [hdfs文件目录] [本地文件目录] # 将hdfs服务器中的文件下载到本地\n&quot;</span> +<br>                <span class="hljs-string">&quot;\n&quot;</span> +<br>                <span class="hljs-string">&quot;put [本地文件目录] [hdfs目录] # 将本地文件上传到hdfs服务器\n&quot;</span> +<br>                <span class="hljs-string">&quot;\n&quot;</span> +<br>                <span class="hljs-string">&quot;del [hdfs文件目录] # 删除hdfs中的文件\n&quot;</span> +<br>                <span class="hljs-string">&quot;\n&quot;</span> +<br>                <span class="hljs-string">&quot;----------------------------------------------------------------------------------&quot;</span>);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        <span class="hljs-type">con</span> <span class="hljs-variable">hdfs</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">con</span>();<br>        String[] s = <span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>[<span class="hljs-number">5</span>];<br>        <span class="hljs-type">int</span> <span class="hljs-variable">len</span> <span class="hljs-operator">=</span> args.length;<br>        <span class="hljs-keyword">if</span> (len &gt;= <span class="hljs-number">1</span>) &#123;<br>            <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; len; ++i)<br>                s[i] = args[i];<br>            <span class="hljs-comment">// 判断命令</span><br>            <span class="hljs-keyword">switch</span> (s[<span class="hljs-number">0</span>]) &#123;<br>                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;ls&quot;</span>:<br><br>                    <span class="hljs-keyword">if</span> (s[<span class="hljs-number">1</span>] == <span class="hljs-string">&quot;&quot;</span>) System.out.println(<span class="hljs-string">&quot;抱歉!第二个参数不能为空! 若查询根目录则为 / \n&quot;</span> + <span class="hljs-string">&quot;ls 命令格式：ls 查询的目录&quot;</span>);<br>                    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (hdfs.isInHdfs(s[<span class="hljs-number">1</span>]))&#123;<br>                        hdfs.remotePath = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(s[<span class="hljs-number">1</span>]);<br>                        hdfs.ls();<br>                    &#125;<br>                    <span class="hljs-keyword">else</span> System.out.println(<span class="hljs-string">&quot;目录&quot;</span>+s[<span class="hljs-number">1</span>] + <span class="hljs-string">&quot; 不存在。&quot;</span>);<br><br>                    <span class="hljs-keyword">break</span>;<br>                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;cat&quot;</span>:<br><br>                    <span class="hljs-keyword">if</span> (s[<span class="hljs-number">1</span>] == <span class="hljs-string">&quot;&quot;</span> || !hdfs.isInHdfs(s[<span class="hljs-number">1</span>])) System.out.println(<span class="hljs-string">&quot;文件 &quot;</span> + s[<span class="hljs-number">1</span>] + <span class="hljs-string">&quot; 不存在&quot;</span>);<br><br>                    <span class="hljs-keyword">else</span> &#123;<br>                        hdfs.filePath = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(s[<span class="hljs-number">1</span>]);<br>                        hdfs.cat();<br>                    &#125;<br>                    <span class="hljs-keyword">break</span>;<br>                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;put&quot;</span>:<br>                    hdfs.localFilePath = s[<span class="hljs-number">1</span>];<br>                    hdfs.remoteFilePath = s[<span class="hljs-number">2</span>];<br>                    hdfs.put();<br>                    <span class="hljs-keyword">break</span>;<br>                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;rm&quot;</span>:<br>                    <span class="hljs-keyword">if</span>(!hdfs.isInHdfs(s[<span class="hljs-number">1</span>])) System.out.println(<span class="hljs-string">&quot;文件 &quot;</span> + s[<span class="hljs-number">1</span>] + <span class="hljs-string">&quot; 不存在&quot;</span>);<br>                    <span class="hljs-keyword">else</span>&#123;<br>                        hdfs.remoteFilePath = s[<span class="hljs-number">1</span>];<br>                        hdfs.rm();<br>                    &#125;<br>                    <span class="hljs-keyword">break</span>;<br>                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;get&quot;</span>:<br>                    <span class="hljs-keyword">if</span> (!hdfs.isInHdfs(s[<span class="hljs-number">1</span>])) System.out.println(<span class="hljs-string">&quot;文件 &quot;</span> + s[<span class="hljs-number">1</span>] + <span class="hljs-string">&quot; 不存在&quot;</span>);<br>                    <span class="hljs-keyword">else</span>&#123;<br>                        hdfs.remoteFilePath = s[<span class="hljs-number">1</span>];<br>                        hdfs.localFilePath = s[<span class="hljs-number">2</span>];<br>                        hdfs.get();<br>                    &#125;<br>                    <span class="hljs-keyword">break</span>;<br>                <span class="hljs-keyword">case</span> <span class="hljs-string">&quot;help&quot;</span>:<br>                    hdfs.help();<br>                    <span class="hljs-keyword">break</span>;<br>                <span class="hljs-keyword">default</span>:<br>                    System.out.println(<span class="hljs-string">&quot;指令有误！提示：输入help可查看jar包支持的命令.&quot;</span>);<br>            &#125;<br>        &#125;<br>        <span class="hljs-keyword">else</span>&#123;<br>            System.out.println(<span class="hljs-string">&quot;请输入有效指令...(输入help可查询jar包操作说明).&quot;</span>);<br>        &#125;<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>




                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/" class="category-chain-item">大数据</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Hadoop/">#Hadoop</a>
      
        <a href="/tags/Java/">#Java</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Hadoop _ Java实现操作 HDFS 读取、获取、下载、上传、删除文件</div>
      <div>http://example.com/2021/04/04/Hadoop _ Java实现操作 HDFS 读取、获取、下载、上传、删除文件/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2021年4月4日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/05/09/Hadoop%20_%20%E5%9F%BA%E4%BA%8EJava%E8%AF%AD%E8%A8%80%E7%9A%84MapReduce%E6%93%8D%E4%BD%9C%E6%A1%88%E4%BE%8B%20_%20%E8%AF%8D%E9%A2%91%E7%BB%9F%E8%AE%A1/" title="Hadoop _ 基于Java语言的MapReduce操作案例 _ 词频统计">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Hadoop _ 基于Java语言的MapReduce操作案例 _ 词频统计</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
